<html>
<head><meta charset="utf-8"><title>non-trivial anonymous constants · project-const-generics · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/index.html">project-const-generics</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html">non-trivial anonymous constants</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="212737329"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/212737329" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#212737329">(Oct 08 2020 at 19:21)</a>:</h4>
<p>We currently emit the following error when encountering a const param outside of an identity expression:</p>
<div class="codehilite"><pre><span></span><code>error: generic parameters must not be used inside of non-trivial constant values
 --&gt; src/lib.rs:4:17
  |
4 |     let x: [u8; N + 1];
  |                 ^ non-trivial anonymous constants must not depend on the parameter `N`
  |
  = help: it is currently only allowed to use either `N` or `{ N }` as generic constants
</code></pre></div>



<a name="212737795"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/212737795" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#212737795">(Oct 08 2020 at 19:25)</a>:</h4>
<p>I am not sure if "non-trivial constant values" is the best way to describe this. I have yet only asked <span class="user-mention" data-user-id="351972">@Ethan Brierley</span> directly who expressed at least some confusion about the current wording</p>



<a name="212737883"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/212737883" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#212737883">(Oct 08 2020 at 19:25)</a>:</h4>
<p>(We should also split that error into two separate ones, one for type params and one for const params)</p>



<a name="212737973"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/212737973" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#212737973">(Oct 08 2020 at 19:26)</a>:</h4>
<p>Potential alternatives would be "const parameters must only be used in identity expressions"</p>



<a name="212738021"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/212738021" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#212738021">(Oct 08 2020 at 19:26)</a>:</h4>
<p>"const parameters must not be used as part of a bigger expression"</p>



<a name="212738052"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/212738052" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#212738052">(Oct 08 2020 at 19:26)</a>:</h4>
<p>do you have any other alternatives here or think that one of the potential alternatives is already good enough?</p>



<a name="212752040"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/212752040" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ethan Brierley <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#212752040">(Oct 08 2020 at 21:33)</a>:</h4>
<p>How does something like this look?</p>
<div class="codehilite"><pre><span></span><code>error: generic parameters must not be used inside of non-trivial constant values
 --&gt; src/lib.rs:4:17
  |
4 |     let x: [u8; N + 1];
  |                 ^^^^^ new constants can not be constructed by expressions dependent on `N`
  |                 ^ `N` is a generic parameter so must only be used in identity expressions
  |
  |
  = help: it is currently only allowed to use either `N` or `{ N }` as generic constants
</code></pre></div>



<a name="212795546"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/212795546" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#212795546">(Oct 09 2020 at 08:20)</a>:</h4>
<p>hmm, do you feel like the term "non-trivial constant values" is useful here?</p>



<a name="212806892"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/212806892" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#212806892">(Oct 09 2020 at 10:24)</a>:</h4>
<p>I definitely feel this diagnostic can be improved. I'll give it some thought later.</p>



<a name="212812416"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/212812416" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ethan Brierley <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#212812416">(Oct 09 2020 at 11:29)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants/near/212795546">said</a>:</p>
<blockquote>
<p>hmm, do you feel like the term "non-trivial constant values" is useful here?</p>
</blockquote>
<p>Probably not. It creates more questions than it answers for me. In future what is trivial is likely to change, making "non-trivial" feel rather undefined.</p>
<p>Also, I don't think of anonymous expressions as values when not made into a variable or something. So "non-trivial const expressions" is probably better than "non-trivial constant values".</p>



<a name="212813561"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/212813561" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#212813561">(Oct 09 2020 at 11:42)</a>:</h4>
<blockquote>
<p>Potential alternatives would be "const parameters must only be used in identity expressions"</p>
</blockquote>
<p>So my best idea as of now would be something like</p>
<div class="codehilite"><pre><span></span><code>error: const parameters must only be used as identity expressions in constants
 --&gt; src/lib.rs:4:17
  |
4 |     let x: [u8; N + 1];
  |                 ^^^^^ not an identity expression
  |
  |
  = help: it is currently only allowed to use either `N` or `{ N }` as generic constants
</code></pre></div>



<a name="212850299"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/212850299" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#212850299">(Oct 09 2020 at 16:52)</a>:</h4>
<p>I think "identity expression" is jargon too.</p>



<a name="212850382"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/212850382" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#212850382">(Oct 09 2020 at 16:53)</a>:</h4>
<p>How about something like:<br>
<code>const parameters may not be used inside expressions</code>?<br>
It's still perhaps a little misleading, because a const parameter <em>is</em> still an expression…</p>



<a name="212851691"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/212851691" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#212851691">(Oct 09 2020 at 17:05)</a>:</h4>
<div class="codehilite"><pre><span></span><code>error: generic parameters must not be used inside of const computations
 --&gt; src/lib.rs:4:17
  |
4 |     let x: [u8; N + 1];
  |                 ^^^^^ cannot perform const operation using `N`
  |
  = help: it is currently only allowed to use either `N` or `{ N }` as generic constants
</code></pre></div>



<a name="212851875"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/212851875" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ethan Brierley <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#212851875">(Oct 09 2020 at 17:06)</a>:</h4>
<p>^^^ This one is very nice imo</p>



<a name="212861266"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/212861266" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#212861266">(Oct 09 2020 at 18:36)</a>:</h4>
<p>Yeah, that works a lot better, I think.</p>



<a name="212861312"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/212861312" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#212861312">(Oct 09 2020 at 18:37)</a>:</h4>
<p>Maybe without the <code>of</code>, just to be a bit more concise.</p>



<a name="212879494"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/212879494" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#212879494">(Oct 09 2020 at 21:50)</a>:</h4>
<p>hmm, I personally don't really like "const computation" here <span aria-label="thinking" class="emoji emoji-1f914" role="img" title="thinking">:thinking:</span> I am however not really the target audience for error messages like this so if they are clearer to people who aren't yet as involved we should just go with that wording.</p>



<a name="212879724"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/212879724" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#212879724">(Oct 09 2020 at 21:53)</a>:</h4>
<p>I think my main issue is that I don't really see <code>N as u128</code> or <code>std::mem::size_of::&lt;T&gt;()</code> as a computations so that name seems inappropriate to me in these cases</p>



<a name="212879751"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/212879751" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#212879751">(Oct 09 2020 at 21:53)</a>:</h4>
<p>A slight adaptation: <code>generic parameters may not be involved in const computations</code>.<br>
I agree "const computation" isn't perfect, but I can't currently think of a better word.</p>



<a name="212879814"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/212879814" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#212879814">(Oct 09 2020 at 21:54)</a>:</h4>
<p>is 'const evaluation' accurate? that seems more well known than 'computation'</p>



<a name="212879853"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/212879853" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#212879853">(Oct 09 2020 at 21:55)</a>:</h4>
<p>I'd also like to reword that help text to something like:<br>
<code>generic consts may only be used as standalone arguments `N` </code></p>



<a name="212879887"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/212879887" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#212879887">(Oct 09 2020 at 21:55)</a>:</h4>
<p><span class="user-mention silent" data-user-id="232545">Joshua Nelson</span> <a href="#narrow/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants/near/212879814">said</a>:</p>
<blockquote>
<p>is 'const evaluation' accurate? that seems more well known than 'computation'</p>
</blockquote>
<p>That could also work.</p>



<a name="212880140"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/212880140" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#212880140">(Oct 09 2020 at 21:59)</a>:</h4>
<p>I think const evaluation seems more correct, so <span aria-label="thumbs up" class="emoji emoji-1f44d" role="img" title="thumbs up">:thumbs_up:</span> on that</p>



<a name="212880258"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/212880258" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#212880258">(Oct 09 2020 at 22:00)</a>:</h4>
<p>As everything except <code>N</code> itself results in <code>ConstKind::Unevaluated</code> which has to be evaluated to be useful</p>



<a name="212880268"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/212880268" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#212880268">(Oct 09 2020 at 22:00)</a>:</h4>
<p>This is the last issue marked as blocking on GH that doesn't have an open PR yet, as far as I see.</p>



<a name="212880312"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/212880312" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#212880312">(Oct 09 2020 at 22:01)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants/near/212880258">said</a>:</p>
<blockquote>
<p>As everything except <code>N</code> itself results in <code>ConstKind::Unevaluated</code> which has to be evaluated to be useful</p>
</blockquote>
<p>One thing to be aware of is that the terminology we use is different to the terminology users are familiar with (though sometimes compiler jargon leaks out into diagnostics, which we need to be careful about). I think "evaluation" is clear though.</p>



<a name="212880801"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/212880801" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#212880801">(Oct 09 2020 at 22:08)</a>:</h4>
<p>I think there is merit in looking at the implementation when thinking about errors but I do agree that we - and probably especially I - have to be careful to not leak internal jargon</p>



<a name="212881329"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/212881329" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#212881329">(Oct 09 2020 at 22:17)</a>:</h4>
<p><span class="user-mention silent" data-user-id="121053">varkor</span> <a href="#narrow/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants/near/212880268">said</a>:</p>
<blockquote>
<p>This is the last issue marked as blocking on GH that doesn't have an open PR yet, as far as I see.</p>
</blockquote>
<p><span class="user-mention" data-user-id="351972">@Ethan Brierley</span> <span class="user-mention" data-user-id="224471">@Lokathor</span>  does using  "const evaluations" also look good to you?</p>
<p>In this case I would be satisfied and would gladly mentor anyone interested in implementing this</p>



<a name="212881429"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/212881429" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#212881429">(Oct 09 2020 at 22:18)</a>:</h4>
<p>It's fine. Even if it weren't, help text isn't stable, so we could fix it up later if we had to. We should just take what we have and move forward.</p>



<a name="212881434"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/212881434" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#212881434">(Oct 09 2020 at 22:19)</a>:</h4>
<div class="codehilite"><pre><span></span><code>error: generic parameters must not be used inside const evaluations
 --&gt; src/lib.rs:4:17
  |
4 |     let x: [u8; N + 1];
  |                 ^^^^^ cannot perform const operation using `N`
  |
  = help: const parameters may only be used as standalone arguments `N`
</code></pre></div>



<a name="212881483"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/212881483" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#212881483">(Oct 09 2020 at 22:19)</a>:</h4>
<p>I'd get rid of <code>of</code>, and maybe the <code>{ N }</code>, since that syntax is rarely necessary (except with paths)</p>



<a name="212881553"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/212881553" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#212881553">(Oct 09 2020 at 22:20)</a>:</h4>
<p>We should instead make sure the diagnostics for writing a path without <code>{ }</code> is good.</p>



<a name="212881563"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/212881563" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#212881563">(Oct 09 2020 at 22:20)</a>:</h4>
<p>Let me check what it currently looks like.</p>



<a name="212881680"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/212881680" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#212881680">(Oct 09 2020 at 22:22)</a>:</h4>
<p>Really not good: <a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=3161a698d4b5aba24beb842c5c064ec4">https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=3161a698d4b5aba24beb842c5c064ec4</a></p>



<a name="212881698"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/212881698" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#212881698">(Oct 09 2020 at 22:22)</a>:</h4>
<div class="codehilite"><pre><span></span><code>error[E0573]: expected type, found constant `m::N`
 --&gt; src/main.rs:9:17
  |
9 |     let _ = S::&lt;m::N&gt;;
  |                 ^^^^ not a type

error[E0107]: wrong number of const arguments: expected 1, found 0
 --&gt; src/main.rs:9:13
  |
9 |     let _ = S::&lt;m::N&gt;;
  |             ^^^^^^^^^ expected 1 const argument

error[E0107]: wrong number of type arguments: expected 0, found 1
 --&gt; src/main.rs:9:17
  |
9 |     let _ = S::&lt;m::N&gt;;
  |                 ^^^^ unexpected type argument
  |
help: If this generic argument was intended as a const parameter, try surrounding it with braces:
  |
9 |     let _ = S::&lt;{ m::N }&gt;;
  |                 ^      ^
</code></pre></div>



<a name="212881714"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/212881714" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#212881714">(Oct 09 2020 at 22:22)</a>:</h4>
<p>We do at least provide a suggestion, though.</p>



<a name="212881737"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/212881737" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#212881737">(Oct 09 2020 at 22:22)</a>:</h4>
<p>I'd love for this to just work.</p>



<a name="212881800"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/212881800" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#212881800">(Oct 09 2020 at 22:23)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants/near/212881434">said</a>:</p>
<blockquote>
<div class="codehilite"><pre><span></span><code>error: generic parameters must not be used inside const evaluations
 --&gt; src/lib.rs:4:17
  |
4 |     let x: [u8; N + 1];
  |                 ^^^^^ cannot perform const operation using `N`
  |
  = help: const parameters may only be used as standalone arguments `N`
</code></pre></div>


</blockquote>
<p>The final change I'd make is "must not" -&gt; "may not", which sounds a little less forceful. But otherwise, I'm happy with that.</p>



<a name="212881857"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/212881857" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#212881857">(Oct 09 2020 at 22:24)</a>:</h4>
<p>We can mark it as an E-easy issue or something.</p>



<a name="212882009"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/212882009" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#212882009">(Oct 09 2020 at 22:26)</a>:</h4>
<p>except if you don't follow directions, the code doesn't compile. so it's a "must".</p>



<a name="212882180"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/212882180" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#212882180">(Oct 09 2020 at 22:28)</a>:</h4>
<p>well, you can read 'may not X' as 'X is not allowed'</p>



<a name="212882185"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/212882185" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#212882185">(Oct 09 2020 at 22:28)</a>:</h4>
<p>You're allowed to do it; the compiler just isn't going to do what you want if you do :P</p>



<a name="212882257"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/212882257" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#212882257">(Oct 09 2020 at 22:29)</a>:</h4>
<p><span class="user-mention silent" data-user-id="121053">varkor</span> <a href="#narrow/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants/near/212881737">said</a>:</p>
<blockquote>
<p>I'd love for this to just work.</p>
</blockquote>
<p>There should probably be a dedicated issue for this, though it's essentially <a href="https://github.com/rust-lang/rust/issues/66615">https://github.com/rust-lang/rust/issues/66615</a></p>



<a name="212882990"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/212882990" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#212882990">(Oct 09 2020 at 22:39)</a>:</h4>
<p>(Opened <a href="https://github.com/rust-lang/rust/issues/77773">https://github.com/rust-lang/rust/issues/77773</a>)</p>



<a name="212886038"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/212886038" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> jplatte <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#212886038">(Oct 09 2020 at 23:29)</a>:</h4>
<p>I would prefer <code>in const evaluation</code> or <code>in constant evaluation</code> over <code>inside const evaluations</code>. Otherwise <span aria-label="+1" class="emoji emoji-1f44d" role="img" title="+1">:+1:</span></p>



<a name="212903925"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/212903925" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ethan Brierley <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#212903925">(Oct 10 2020 at 07:42)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants/near/212881329">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="121053">varkor</span> <a href="#narrow/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants/near/212880268">said</a>:</p>
<blockquote>
<p>This is the last issue marked as blocking on GH that doesn't have an open PR yet, as far as I see.</p>
</blockquote>
<p><span class="user-mention silent" data-user-id="351972">Ethan Brierley</span> <span class="user-mention silent" data-user-id="224471">Lokathor</span>  does using  "const evaluations" also look good to you?</p>
<p>In this case I would be satisfied and would gladly mentor anyone interested in implementing this</p>
</blockquote>
<p>I have never made changes to rustc before and would love to work on this.</p>



<a name="212903976"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/212903976" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ethan Brierley <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#212903976">(Oct 10 2020 at 07:44)</a>:</h4>
<p>I will do some searching through the code later today to try to find the relevant code.</p>



<a name="212905129"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/212905129" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#212905129">(Oct 10 2020 at 08:20)</a>:</h4>
<p><span class="user-mention" data-user-id="351972">@Ethan Brierley</span> great! Feel free to ask me if you ever get stuck somewhere <span aria-label="thumbs up" class="emoji emoji-1f44d" role="img" title="thumbs up">:thumbs_up:</span></p>



<a name="212906526"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/212906526" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ethan Brierley <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#212906526">(Oct 10 2020 at 09:01)</a>:</h4>
<p>Thank you</p>



<a name="213010637"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/213010637" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#213010637">(Oct 12 2020 at 08:30)</a>:</h4>
<p>resolved with <a href="https://github.com/rust-lang/rust/issues/77825">#77825</a> by <span class="user-mention silent" data-user-id="351972">Ethan Brierley</span> <span aria-label="thumbs up" class="emoji emoji-1f44d" role="img" title="thumbs up">:thumbs_up:</span></p>



<a name="213028959"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/213028959" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#213028959">(Oct 12 2020 at 12:03)</a>:</h4>
<p>Sorry, I realised when I saw more examples that I think there were still some readability issues with what we'd suggested before. I think this error is going to be quite common, so we need to make sure it's as clear as possible. Hope it's okay for us to iterate a little more!</p>



<a name="213031327"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/213031327" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ethan Brierley <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#213031327">(Oct 12 2020 at 12:29)</a>:</h4>
<p>What are everyone's thoughts on <a href="https://github.com/rust-lang/rust/pull/77825/files#r503246680">https://github.com/rust-lang/rust/pull/77825/files#r503246680</a> ?</p>



<a name="213031505"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/213031505" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#213031505">(Oct 12 2020 at 12:31)</a>:</h4>
<p>The comment in the link above was:</p>
<blockquote>
<p>I want to further suggest switching from "evaluation" to "operations", which I think is slightly less jargon-y, and also consistent with the span_label below.</p>
</blockquote>



<a name="213031548"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/213031548" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#213031548">(Oct 12 2020 at 12:31)</a>:</h4>
<p>I do agree that it may be confusable with "operators", so it's still not perfect.</p>



<a name="213031643"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/213031643" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#213031643">(Oct 12 2020 at 12:32)</a>:</h4>
<p>I just realised that Rust programmers in general probably aren't used to thinking of the length of an array as a "const evaluation".</p>



<a name="213031739"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/213031739" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#213031739">(Oct 12 2020 at 12:33)</a>:</h4>
<p>I actually think "const expression" might be clear enough.</p>



<a name="213031756"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/213031756" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#213031756">(Oct 12 2020 at 12:33)</a>:</h4>
<p>(The "nontrivial" part would be implicit.)</p>



<a name="213032176"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/213032176" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ethan Brierley <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#213032176">(Oct 12 2020 at 12:37)</a>:</h4>
<p>I don't think expression is clear enough with, the thing we allow, <code>N</code> on its own being also a kind of expression. In other words I don't think the nontrivial part can become implicit.</p>



<a name="213032458"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/213032458" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#213032458">(Oct 12 2020 at 12:40)</a>:</h4>
<p>"generic parameters may not be used as part of a larger const expression"</p>



<a name="213032474"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/non-trivial%20anonymous%20constants/near/213032474" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants.html#213032474">(Oct 12 2020 at 12:40)</a>:</h4>
<p>It's a little long.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>